mui.init({
    pullRefresh: {
        container: "#refreshContainer", //待刷新区域标识，querySelector能定位的css选择器均可，比如：id、.class等
        up: {
            height: 50, //可选.默认50.触发上拉加载拖动距离
            auto: false, //可选,默认false.自动上拉加载一次
            contentrefresh: "正在加载...", //可选，正在加载状态时，上拉加载控件上显示的标题内容
            contentnomore: '没有更多数据了', //可选，请求完毕若没有更多数据时显示的提醒内容；
            callback: function () {
                VM.get_get_wrong_question_lists();
                setTimeout(function () {
                    mui('#refreshContainer').pullRefresh().endPulldownToRefresh(false);
                },1000)
            }
        }
    }
});

var VM = '';
var Fpage = 1;
var Cpage = 1;
mui.plusReady(function () {
    VM = new Vue({
        el: '#QUEdata',
        data: {
            cuoti_dataLists: [],
            collect_dataLists: [],
            tabIndex: 1
        },
        watch: {
            tabIndex: function (val, oldVal) {
                if (val == 2) {
                    if (this.collect_dataLists.length == 0) {
                        this.get_collections_question_lists();
                    }
                }
            }
        },
        mounted: function () {
            this.get_get_wrong_question_lists();
        },
        methods: {
            get_get_wrong_question_lists: function () {
                showWatting();
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/questionbank/public/get_wrong_question_lists',
                    dataType: 'json',
                    data: {'page': Fpage},
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            VM.cuoti_dataLists = msg.data;
                        } else {
                            mui.toast(msg.msg, {duration: '200',type: 'div'});
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('加载失败!', {duration: '200',type: 'div'});
                    },
                    complete: function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            get_collections_question_lists: function () {
                var api_host = plus.storage.getItem('HOST_URL');
                mui.ajax({
                    url: api_host + '/api/questionbank/public/get_collections_question_lists',
                    dataType: 'json',
                    data: {'page': Cpage},
                    headers:{'User-Token':plus.storage.getItem('UserToken')},
                    timeout:3000,
                    type: 'get',
                    success: function (msg) {
                        if (msg.code == 1) {
                            VM.collect_dataLists = msg.data;
                        } else {
                            mui.toast(msg.msg, {duration: '200',type: 'div'});
                        }
                    },
                    error: function (xhr, type, errorThrown) {
                        mui.toast('加载失败!', {duration: '200',type: 'div'});
                    },
                    complete: function () {
                        plus.nativeUI.closeWaiting();
                    }
                });
            },
            open_question_details: function (re, type, id) {
                mui.openWindow({
                    url: 'onesCategoryQuestionDetails.html',
                    extras: {
                        're': re,
                        'type': type,
                        'dataID': id,
                    },
                    createNew: false,
                    show: {
                        autoShow: true,
                        aniShow: 'pop-in',
                        duration: 400
                    },
                    waiting: {
                        autoShow: false,
                    }
                })
            }
        }
    })
})

mui('.mui-slider').on('tap', '.ctscTab', function () {
    VM.tabIndex = $(this).attr('data-index');
})

//上拉加载函数
function pullfreshData() {
    if (VM.tabIndex == 1) {
        Fpage++;
        VM.get_get_wrong_question_lists();
    } else if (VM.tabIndex == 2) {
        Cpage++;
        VM.get_get_wrong_question_lists();
    }
}